<template>
  <div>
    <h4 class="boardName">当日报警
      <a-icon type="right" />
    </h4>
    <div class=" lightBox newquipmentBox">
      <!--              环形图-->
      <div style="width: 60%;float: left;padding-top:50px">
        <pieCharts v-if="pieData.length>0" :chartData="pieData" :chartColor="colorList" :height="'200px'" />
      </div>
      <!--              环形图图例-->
      <div style="width: 40%;float: left;" class="pielegendbox">
        <p class="pielegend" v-for="(item,index) in pieData" :key="index">
          <span class="name">{{ item.name }}</span><span class="value">{{ item.str||0 }}个</span>
        </p>
      </div>
    </div>
  </div>
</template>
<script>
import pieCharts from "../../../echartsCom/pieCharts.vue";

let colorList = ["#FF3535", "#FF7865", "#FFBB00", "#f8d77e"];
export default {
  name: "index",
  props:{
    AlarmList:{
      type:Array,
      default:()=>[]
    }
  },
  components: {
    pieCharts
  },
  watch:{
    AlarmList(val){
      this.AlarmListIn(val)
    }
  },
  data() {
    return {
      userName: "",
      name: "",
      role: "",
      compId: "",
      dateType: 1,
      pieData: [{ value: "3", name: "一级报警" }, { value: "4", name: "二级报警" }, { value: "6", name: "三级报警" }, {
        value: "2",
        name: "系统提示信息"
      }],
      colorList: colorList
    };
  },
  methods:{
    AlarmListIn(list) {
      let data = [{ value: "0", name: "一级报警" }, { value: "0", name: "二级报警" }, { value: "0", name: "三级报警" }, {
        value: "0",
        name: "系统提示信息"
      }];
      list.forEach((item, index) => {
        if (item.alarmType == 1) {
          data[0].value = (item.rate * 100).toFixed(2);
          data[0].str =item.count;
        } else if (item.alarmType == 2) {
          data[1].value = (item.rate * 100).toFixed(2);
           data[1].str =item.count;
        } else if (item.alarmType == 3) {
          data[2].value = (item.rate * 100).toFixed(2);
           data[2].str =item.count;
        } else if (item.alarmType == 4) {
          data[3].value = (item.rate * 100).toFixed(2);
           data[3].str =item.count;
        }
      });
      this.pieData = data;
    }
  }
};
</script>

<style scoped lang="less">
@import "../../light.less";
</style>
